﻿Public Class Map
    Structure DecalStruc
        Dim Pos As Point
        Dim Rectangle As Rectangle
        Dim Texture As Texture2D
    End Structure
    Public Const TileSize As Integer = 64
    Public map(21, 21) As Integer

    '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _
    '{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}

    Public TileMap(,) As Tile
    Private Decals() As DecalStruc

    Public Sub IntialiseMap(BlankText As Texture2D, GroundText As Texture2D, decal As Texture2D)

        Dim rand As New Random


        ReDim TileMap(21, 21)
        For u = 0 To 21
            For j = 0 To 21
                If u = 0 Then
                    map(u, j) = 1
                    TileMap(u, j) = New Tile
                ElseIf j = 0 Then
                    map(u, j) = 1
                    TileMap(u, j) = New Tile
                ElseIf u = 21 Then
                    map(u, j) = 1
                    TileMap(u, j) = New Tile
                ElseIf j = 21 Then
                    map(u, j) = 1
                    TileMap(u, j) = New Tile
                Else
                    map(u, j) = 0
                    TileMap(u, j) = New Tile
                End If
            Next
        Next


        For i = 0 To 10
            map(rand.Next(1, 20), rand.Next(1, 20)) = 1
        Next

        For x = 0 To 21
            For y = 0 To 21
                Select Case map(x, y)
                    Case 0
                        TileMap(x, y).InitTile(New Point(y * TileSize, x * TileSize), BlankText, TileSize)
                    Case 1
                        TileMap(x, y).InitTile(New Point(y * TileSize, x * TileSize), GroundText, TileSize)
                        TileMap(x, y).Type = "block"
                        TileMap(x, y).Rectangle = New Rectangle(y * TileSize, x * TileSize, TileSize, TileSize)
                    Case 2

                End Select
            Next
        Next

        ReDim Decals(10)
        'moved upwards        Dim rand As New Random
        For i = 0 To 10
            Decals(i).Pos = New Point(rand.Next(100, 1000), rand.Next(100, 1000))
            Decals(i).Rectangle = New Rectangle(Decals(i).Pos.X, Decals(i).Pos.Y, decal.Width, decal.Height)
            Decals(i).Texture = decal
        Next
        'Decals(1).Pos = New Point(rand.Next(100, 1000), rand.Next(100, 1000)) ' New Point(100, 750)
        'Decals(1).Rectangle = New Rectangle(Decals(1).Pos.X, Decals(1).Pos.Y, decal.Width, decal.Height)
        'Decals(1).Texture = decal
    End Sub


    Public Sub DrawMap(spritebatch As SpriteBatch, Parsed_Light As Color)
        Dim Rand As New Random
        For i = 0 To 10
            spritebatch.Draw(Decals(i).Texture, Decals(i).Rectangle, Parsed_Light)
            ' spritebatch.Draw(Decals(i).Texture, Decals(i).Rectangle, Decals(i).Rectangle, Parsed_Light, MathHelper.ToRadians(Rand.Next(0, 90)), New Vector2(Decals(i).Texture.Width / 2, Decals(i).Texture.Height / 2), SpriteEffects.None, 0)
        Next

        For x = 0 To 21
            For y = 0 To 21
                If TileMap(x, y).State = "hit" Then
                    spritebatch.Draw(TileMap(x, y).Texture, TileMap(x, y).Rectangle, Color.Red)
                Else
                    spritebatch.Draw(TileMap(x, y).Texture, TileMap(x, y).Rectangle, Parsed_Light)
                End If

            Next
        Next

    End Sub

End Class
